package com.lixin.controller;

import com.lixin.pojo.dto.UserLoginDto;
import com.lixin.pojo.dto.UserModifyDto;
import com.lixin.pojo.dto.UserRegisterDto;
import com.lixin.service.UserService;
import com.lixin.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("detail")
    public Result detail() {
        return userService.detail();
    }

    @PostMapping("modify")
    public Result Modify(@RequestBody UserModifyDto userModifyDto, @RequestHeader("Authorization") String token) {
        return userService.modify(userModifyDto, token);
    }

    @GetMapping
    public Result index(String currentPage, String pageSize) {
        return userService.findWithPage(currentPage, pageSize);
    }

    @PostMapping("register")
    public Result register(@RequestBody UserRegisterDto userRegisterDto) {
        return userService.register(userRegisterDto);
    }

    @PostMapping("login")
    public Result login(@RequestBody UserLoginDto userLoginDto) {
        return userService.login(userLoginDto);
    }

    @GetMapping("check_account")
    public Result checkAccount(String account) {
        return userService.checkAccount(account);
    }

    @GetMapping("del")
    public Result del(String id) {
        return userService.del(id);
    }

    @GetMapping("test")
    public Result test(UserLoginDto userLoginDto) {
        return Result.success(userLoginDto);
    }
}
